'use strict';

/**
 * @name 后台请求的resource
 * @description 向后台发请求的文件
 * @author Yud
 */
angular.module('metalabPartnerApp').factory('MetaResources', ['$resource', function ($resource) {
    var resources = {};

    var _host = CONFIG.apiHost;

    //收藏Favorite的接口
    resources.favorite = $resource(_host, null, {
        'get': {
            url: _host + '/favourites/:id',
            method: 'GET',
            isArray: false
        },
        'delete': {
            url: _host + '/favourites/:id',
            method: 'DELETE'
        },
        'query': {
            url: _host + '/users/:userId/favourites',
            method: 'GET',
            isArray: true
        },
        'add': {
            url: _host + '/users/:userId/favourites/',
            method: 'POST'
        },
        'exist': {
            url: _host + '/users/:userId/favourites/exist',
            method: 'GET'
        }
    });

    resources.statistic = $resource(_host, null, {
        'userAction': {
            url: _host + '/user_actions',
            method: 'POST'
        }
    });

    //有效性标签effectTag的接口
    resources.effectTages = $resource(_host, null, {
        'get': {
            url: _host + '/technologies/effect_tags',
            method: 'GET',
            isArray: true
        }
    });

    //search
    resources.search = $resource(_host, null, {
        'website': {
            url: _host + '/search/website_search',
            method: 'POST',
            isArray: true
        },
        'segment': {
            url: _host + '/search/segment',
            header: {
                'x-field-style': 'camelcase'
            },
            method: 'GET',
            isArray: true
        },
        'engine': {
            url: _host + '/search/engine',
            header: {
                'x-field-style': 'camelcase'
            },
            method: 'POST',
            isArray: false
        }
    });

    //进程process接口
    resources.process = $resource(_host, null, {
        'process': {//查看某个进程
            url: _host + '/solution_processes/:id',
            method: 'GET',
            isArray: false
        },
        'processes': {//查看进程列表
            url: _host + '/solution_processes',
            method: 'GET',
            isArray: true
        },
        'userProcess': {//用户的进程列表
            url: _host + '/users/:user_id/solution_processes',
            method: 'GET',
            isArray: true
        },
        'demandProcess': {//查看需求方进程
            url: _host + '/demand_side_processes/:id',
            method: 'GET',
            isArray: false
        },
        'demandProcessAdd': {//向技术方案提交需求
            url: _host + '/technologies/:technologyId/solution_processes',
            method: 'POST',
            isArray: false
        },
        'demandProcesses': {//需求正在进行的进程列表
            url: _host + '/demands/:demandId/solution_processes',
            method: 'GET',
            isArray: true
        },
        'demandProcessUpdate': {//更新需求方进程
            url: _host + '/demand_side_processes/:id',
            method: 'PUT',
            isArray: false
        },
        'technologyProcess': {//查看技术方进程
            url: _host + '/technology_side_processes/:id',
            method: 'GET',
            isArray: false
        },
        'technologyProcessAdd': {//向需求提交技术方案
            url: _host + '/demands/:demandId/solution_processes',
            method: 'POST',
            isArray: false
        },
        'technologyProgresses': {//技术方案正在进行的进程列表
            url: _host + '/projects/:projectId/solution_processes',
            method: 'GET',
            isArray: true
        },
        'technologyProcessUpdate': {//更新技术方进程
            url: _host + '/technology_side_processes/:id',
            method: 'PUT',
            isArray: false
        },
        'projectProcesses': {//查看项目的进程列表
            url: _host + '/projects/:projectId/solution_processes',
            method: 'GET',
            isArray: true
        }
    });

    //进程备注solution process note接口
    resources.note = $resource(_host, null, {
        'add': {
            url: _host + '/users/:userId/solution_process_notes',
            method: 'POST',
            isArray: false
        },
        'delete': {
            url: _host + '/solution_process_notes/:id',
            method: 'DELETE',
            isArray: false
        },
        'update': {
            url: _host + '/solution_process_notes/:id',
            method: 'PUT',
            isArray: false
        },
        'query': {
            url: _host + '/solution_process_notes/:id',
            method: 'GET',
            isArray: false
        },
        'get': {
            url: _host + '/users/:userId/solution_process_notes',
            method: 'GET',
            isArray: true
        }
    });

    //项目project接口
    resources.project = $resource(_host, null, {//用户的项目列表
        'query': {
            url: _host + '/users/:userId/projects',
            method: 'get',
            isArray: true
        }
    });

    //需求resource接口
    resources.demand = $resource(_host, null, {
        'query': {
            url: _host + '/demands',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/demands/:demandId',
            method: 'GET',
            isArray: false
        },

        'queryMore': {
            url: _host + '/users/:userId/demands',
            method: 'get',
            isArray: true
        },
        'create': {
            url: _host + '/users/:userId/demands',
            method: 'POST',
            isArray: false
        },
        'update': {},
        'delete': {}
    });

    //技术方案的resource接口
    resources.technology = $resource(_host + '', null, {
        'query': {
            url: _host + '/technologies',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/technologies/:technologyId',
            method: 'GET',
            isArray: false
        },
        'queryMore': {
            url: _host + '/users/:userId/technologies',
            method: 'get',
            isArray: true
        },
        'create': {
            url: _host + '/users/:userId/technologies',
            method: 'POST',
            isArray: false
        },
        'update': {},
        'delete': {},
        'origin': {
            url: _host + '/technologies/origins',
            method: 'GET',
            isArray: true
        }
    });

    //技术资源的resource接口
    resources.talent = $resource(_host + '', null, {
        'query': {
            url: _host + '/talents',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/talents/:id',
            method: 'GET',
            isArray: false
        },
        'getByUser': {
            url: _host + '/users/:userId/talent',
            method: 'GET',
            isArray: false
        },
        'open': {
            url: _host + '/users/:userId/talent',
            method: 'POST',
            isArray: false
        },
        'update': {
            url: _host + '/users/:userId/talent',
            method: 'PUT',
            isArray: false
        },
        'delete': {}
    });

    //科研成果的resource接口
    resources.achievement = $resource(_host + '', null, {
        'query': {
            url: _host + '/talents/:talentId/achievements',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/achievements/:id',
            method: 'GET',
            isArray: false
        },
        'create': {
            url: _host + '/talents/:talentId/achievements',
            method: 'POST',
            isArray: false
        },
        'update': {
            url: _host + '/achievements/:id',
            method: 'PUT',
            isArray: false
        },
        'delete': {
            url: _host + '/achievements/:id',
            method: 'DELETE'
        }
    });

    resources.researchArea = $resource('', null, {
        'query': {
            url: _host + '/talents/:talentId/research_areas',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/research_areas/:id',
            method: 'GET',
            isArray: false
        },
        create: {
            url: _host + '/talents/:talentId/research_areas',
            method: 'POST',
            isArray: false
        },
        update: {
            url: _host + '/research_areas/:id',
            method: 'PUT',
            isArray: false
        },
        delete: {
            url: _host + '/research_areas/:id',
            method: 'DELETE',
            isArray: false
        }
    });

    //消息的resource接口
    resources.message = $resource(_host + '', null, {
        'query': {
            url: _host + '/message/:user_id',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/achievements/:id',
            method: 'GET',
            isArray: false
        },
        'read': {
            url: _host + 'messages/:id/read',
            method: 'POST',
            isArray: false
        },
        'update': {},
        'delete': {}
    });

    //账户的resource接口
    resources.account = $resource(_host + '', null, {
        'query': {
            url: _host + '/account/:user_id',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/achievements/:id',
            method: 'GET',
            isArray: false
        },
        'create': {},
        'update': {},
        'delete': {}
    });

    resources.passport = $resource('', null, {
        'message': {
            url: _host + '/user_identities/send_mobile_code',
            method: 'POST',
            isArray: true
        },
        'signIn': {
            url: _host + '/user_identities/login',
            method: 'POST',
            isArray: false
        },
        'signUp': {
            url: _host + '/user_identities/register',
            method: 'POST',
            isArray: false
        },
        'resetPassword': {
            url: _host + '/user_identities/regain_password',
            method: 'POST',
            isArray: false
        }
    });

    //用户user相关接口
    resources.user = $resource('', null, {
        'get': {
            url: _host + '/users/:id'
        },
        'update': {
            url: _host + '/users/:id',
            method: 'PUT',
            isArray: false
        },
        'updatePassword': {
            url: _host + '/users/:userId/update_password',
            method: 'PUT',
            isArray: false
        }
    });

    //账户基金
    resources.accountRecord = $resource('', null, {
        'query': {
            url: _host + '/users/:userId/account_records',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/account_records/:id',
            method: 'GET',
            isArray: false
        }
    });

    //消息模块
    resources.message = $resource('', null, {
        'query': {
            url: _host + '/users/:userId/messages',
            method: 'GET',
            isArray: true
        },
        'read': {
            url: _host + '/messages/:id/read',
            method: 'POST',
            isArray: false
        }
    });

    return resources;
}]);
